package com.project.common.domain;

import cn.dev33.satoken.stp.StpUtil;
import com.project.common.domain.po.BasePO;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;

public class DataSearchScopeAware {
    @PrePersist
    private void prePersist(BasePO entity) {
        if(StpUtil.getExtra("roleKeys")!=null){
            entity.setRoleKeys(StpUtil.getExtra("roleKeys").toString());
        }
        if(StpUtil.getExtra("orgKey")!=null){
            entity.setOrgKey(StpUtil.getExtra("orgKey").toString());
        }
    }

    @PreUpdate
    private void preUpdate(BasePO entity) {
        if(StpUtil.getExtra("roleKeys")!=null){
            entity.setRoleKeys(StpUtil.getExtra("roleKeys").toString());
        }
        if(StpUtil.getExtra("orgKey")!=null){
            entity.setOrgKey(StpUtil.getExtra("orgKey").toString());
        }
    }
}
